#include "topdbs_factory.hpp"
#include "topdbs_factory_imp.hpp"

namespace topdbs
{
	topdbs_connection_factory::topdbs_connection_factory(eDBSClient_t dbsClient)
	{
		m_pFactory = createFacotry(dbsClient);
	}

	topdbs_connection_factory::~topdbs_connection_factory()
	{
		if(m_pFactory) {
			delete m_pFactory;
			m_pFactory = nullptr;
		}
	}
	topdbs_base_connection* topdbs_connection_factory::create()
	{
		try
		{
			return m_pFactory? m_pFactory->CreateConnection() : nullptr;
		}
		catch(const std::exception& e)
		{
			dbslog(DBS_ERROR,"CreateConnection exception:%s",e.what());
		}
		catch(const char* psError)
		{
			dbslog(DBS_ERROR,"CreateConnection exception:%s",psError);
		}
		return nullptr;
	}

	topdbs_session_factory::topdbs_session_factory(eDBSClient_t dbsClient)
	{
		m_pFactory = createFacotry(dbsClient);
	}

	topdbs_session_factory::~topdbs_session_factory()
	{
		if(m_pFactory) {
			delete m_pFactory;
			m_pFactory = nullptr;
		}
	}

	topdbs_base_session* topdbs_session_factory::create(topdbs_base_connection* pConnection)
	{
		if(!pConnection) return nullptr;
		try
		{
			return m_pFactory? m_pFactory->CreateSession(pConnection) : nullptr;
		}
		catch(const std::exception& e)
		{
			dbslog(DBS_ERROR,"CreateSession exception:%s",e.what());
		}
		catch(const char* psError)
		{
			dbslog(DBS_ERROR,"CreateSession exception:%s",psError);
		}	
		return nullptr;	
	}
}
